<template>
	<view>
		<view class="zy-detail-card">
			<view class="zy-detail-card-title zy-text-bold zy-text-big">
				{{item.title}}
			</view>
			<view v-html="item.content"></view>
			<view class="zy-text-info zy-detail-card-time" v-text="item.createTime"></view>
		</view>
	</view>
</template>

<script>
	import {
		doGet,
		FRONT_BASE_URL,
		LOCAL_FILE_STORAGE
	} from '@/common/util.js'
	import * as ResponseStatus from '@/common/response-status.js'
	export default {
		data() {
			return {
				item: {},
				frontBaseUrl: FRONT_BASE_URL,
				localFileStorage: LOCAL_FILE_STORAGE,
				noticeId: null
			}
		},
		onLoad(event) {
			uni.hideShareMenu();
			this.noticeId = event.noticeId
			// TODO 后面把参数名替换成 payload
			const payload = event.itemData || event.payload;
			// 目前在某些平台参数会被主动 decode，暂时这样处理。
			if (payload) {
				try {
					this.item = JSON.parse(decodeURIComponent(payload));
				} catch (error) {
					this.item = JSON.parse(payload);
				}
				this.item.content = this.item.content.replace(/\/upload/g, FRONT_BASE_URL + 'upload')
				uni.setNavigationBarTitle({
					title: this.item.title
				})
			}
			if (this.noticeId) {
				console.log(this.noticeId)
				this.loadNotice()
			}
		},
		methods: {
			loadNotice() {
				doGet('/notice/any/one/' + this.noticeId, {}, {}, false).then(response => {
					let [err, res] = response
					if (res.data.code === ResponseStatus.OK) {
						this.item = res.data.data
						this.item.content = this.item.content.replace(/\/upload/g, FRONT_BASE_URL + 'upload')
						uni.setNavigationBarTitle({
							title: this.item.title
						})
					}
				}).catch(error => {
					console.log(error)
				})
			}
		}
	}
</script>

<style lang="scss">
	@import '@/common/zywork-main.scss';
</style>
